//
//  YBRequestManager.m
//  ZhongWangYuanApp
//
//  Created by apple on 18/6/2.
//  Copyright © 2018年 apple. All rights reserved.
//

#import "YBRequestManager.h"

@implementation YBRequestManager

#pragma mark 登录
+ (void)request_loginWithUsername:(NSString *)username password:(NSString *)password successBlock:(NetBlock)successBlock failBlock:(NetBlock)failBlock{
    NSMutableDictionary * dic = [NSMutableDictionary dictionary];
    [dic setValue:@"wechatapp" forKey:@"clienttype"];
    [dic setValue:username forKey:@"logname"];
    NSData *data = [password dataUsingEncoding:NSUTF8StringEncoding];
    //base64加密编码
    NSString *stringBase64 = [data base64EncodedStringWithOptions:NSDataBase64Encoding64CharacterLineLength];
    [dic setValue:stringBase64 forKey:@"password"];
    [dic setValue:@"" forKey:@"inputyzmcode"];
    [YBAFNetWorkingTool loginPostWithUrlString:@"login" Parameter:dic Success:successBlock Fail:failBlock];
}

#pragma mark 获取sessionId
+ (void)request_sessionIdWithSuccessBlock:(NetBlock)successBlock failBlock:(NetBlock)failBlock{
    NSMutableDictionary * dic = [NSMutableDictionary dictionary];
    [YBAFNetWorkingTool postWithUrlString:@"GetSessionId" Parameter:dic Success:successBlock Fail:failBlock];
}

#pragma mark 获取version
+ (void)request_versionWithSuccessBlock:(NetBlock)successBlock failBlock:(NetBlock)failBlock{
    NSMutableDictionary * dic = [NSMutableDictionary dictionary];
    [YBAFNetWorkingTool postWithUrlString:@"GetVersionData" Parameter:dic Success:successBlock Fail:failBlock];
}

#pragma mark 发送短信验证码
+ (void)request_sendVerifySMSCodeWithPhone:(NSString *)phone successBlock:(NetBlock)successBlock failBlock:(NetBlock)failBlock{
    NSMutableDictionary * dic = [NSMutableDictionary dictionary];
    [dic setValue:phone forKey:@"phone"];
    [dic setValue:@"validatesmscode" forKey:@"keyname"];
    [YBAFNetWorkingTool postWithUrlString:@"verifySMSCode" Parameter:dic Success:successBlock Fail:failBlock];
}

#pragma mark 激活帐号
+ (void)request_activationAccountWithUsername:(NSString *)username password:(NSString *)password name:(NSString *)name inputyzmcode:(NSString *)inputyzmcode inputsmscode:(NSString *)inputsmscode cellphone:(NSString *)cellphone successBlock:(NetBlock)successBlock failBlock:(NetBlock)failBlock{
    NSMutableDictionary * dic = [NSMutableDictionary dictionary];
    [dic setValue:name forKey:@"name"];
    [dic setValue:inputyzmcode forKey:@"inputyzmcode"];
    [dic setValue:inputsmscode forKey:@"inputsmscode"];
    [dic setValue:cellphone forKey:@"cellphone"];
//    [dic setValue:@"wechat" forKey:@"clienttype"];
    NSData *data = [password dataUsingEncoding:NSUTF8StringEncoding];
    //base64加密编码
    NSString *stringBase64 = [data base64EncodedStringWithOptions:NSDataBase64Encoding64CharacterLineLength];
    [YBAFNetWorkingTool postWithUrlString:@"Active" Parameter:@{@"loginObj" : @{@"logname" : username , @"password" : stringBase64 , @"inputyzmcode":@""} , @"activeObj" : [dic copy]} Success:successBlock Fail:failBlock];
    
}


#pragma mark 找回密码
+ (void)request_findPasswordWithCellphone:(NSString *)cellphone password:(NSString *)password inputsmscode:(NSString *)inputsmscode successBlock:(NetBlock)successBlock failBlock:(NetBlock)failBlock{
    NSMutableDictionary * dic = [NSMutableDictionary dictionary];
    [dic setValue:inputsmscode forKey:@"inputsmscode"];
    [dic setValue:cellphone forKey:@"cellphone"];
    NSData *data = [password dataUsingEncoding:NSUTF8StringEncoding];
    //base64加密编码
    NSString *stringBase64 = [data base64EncodedStringWithOptions:NSDataBase64Encoding64CharacterLineLength];
    [dic setValue:stringBase64 forKey:@"password"];
    [YBAFNetWorkingTool postWithUrlString:@"appresetuserpwd" Parameter:dic Success:successBlock Fail:failBlock];
    
}

#pragma mark 修改姓名
+ (void)request_changeNameWithName:(NSString *)name successBlock:(NetBlock)successBlock failBlock:(NetBlock)failBlock{
    NSMutableDictionary * dic = [NSMutableDictionary dictionary];
    [dic setValue:YBUSERINFOMODEL.accountId forKey:@"accountid"];
//    [dic setValue:[name stringByAddingPercentEncodingWithAllowedCharacters:[NSCharacterSet URLQueryAllowedCharacterSet]] forKey:@"name"];
    [dic setValue:name forKey:@"name"];
    [YBAFNetWorkingTool postWithUrlString:@"changename" Parameter:dic Success:successBlock Fail:failBlock];
}

#pragma mark 修改手机号
+ (void)request_changePhoneNumberWithPhoneNumber:(NSString *)phoneNumber inputsmscode:(NSString *)inputsmscode successBlock:(NetBlock)successBlock failBlock:(NetBlock)failBlock{
    NSMutableDictionary * dic = [NSMutableDictionary dictionary];
    [dic setValue:YBUSERINFOMODEL.accountId forKey:@"accountid"];
    [dic setValue:phoneNumber forKey:@"telphone"];
    [dic setValue:inputsmscode forKey:@"inputsmscode"];
    [dic setValue:@"" forKey:@"message"];
    [YBAFNetWorkingTool postWithUrlString:@"changetelphone" Parameter:dic Success:successBlock Fail:failBlock];
}

#pragma mark 修改密码
+ (void)request_changePasswordWithOldPassword:(NSString *)oldPassword newPassword:(NSString *)newPassword againPassword:(NSString *)againPassword successBlock:(NetBlock)successBlock failBlock:(NetBlock)failBlock{
    NSMutableDictionary * dic = [NSMutableDictionary dictionary];
    [dic setValue:YBUSERINFOMODEL.accountId forKey:@"accountid"];
    
    NSData *oldData = [oldPassword dataUsingEncoding:NSUTF8StringEncoding];
    //base64加密编码
    NSString *oldStringBase64 = [oldData base64EncodedStringWithOptions:NSDataBase64Encoding64CharacterLineLength];
    [dic setValue:oldStringBase64 forKey:@"sourcepassword"];
    
    NSData *newData = [newPassword dataUsingEncoding:NSUTF8StringEncoding];
    //base64加密编码
    NSString *newStringBase64 = [newData base64EncodedStringWithOptions:NSDataBase64Encoding64CharacterLineLength];
    [dic setValue:newStringBase64 forKey:@"password"];
    
    NSData *againData = [againPassword dataUsingEncoding:NSUTF8StringEncoding];
    //base64加密编码
    NSString *againStringBase64 = [againData base64EncodedStringWithOptions:NSDataBase64Encoding64CharacterLineLength];
    [dic setValue:againStringBase64 forKey:@"confirmpassword"];
    
    [YBAFNetWorkingTool postWithUrlString:@"changepassword" Parameter:dic Success:successBlock Fail:failBlock];
}

#pragma mark 专题详情
+ (void)request_objectDetailWithIdString:(NSString *)idString successBlock:(NetBlock)successBlock failBlock:(NetBlock)failBlock{
    NSMutableDictionary * dic = [NSMutableDictionary dictionary];
    [dic setValue:YBUSERINFOMODEL.studentId forKey:@"studentid"];
    [dic setValue:idString forKey:@"classid"];
    [YBAFNetWorkingTool postWithUrlString:@"getAppTopicClassInfo" Parameter:dic Success:successBlock Fail:failBlock];
}

#pragma mark 专题基本信息
+ (void)request_classBasicInfoWithIdString:(NSString *)idString successBlock:(NetBlock)successBlock failBlock:(NetBlock)failBlock{
    NSMutableDictionary * dic = [NSMutableDictionary dictionary];
    [dic setValue:idString forKey:@"id"];
    [YBAFNetWorkingTool postWithUrlString:@"getTopicClassInfoAPP" Parameter:dic Success:successBlock Fail:failBlock];
}


#pragma mark 专题课程
+ (void)request_objectClassWithIdString:(NSString *)idString pageindex:(NSString *)pageindex successBlock:(NetBlock)successBlock failBlock:(NetBlock)failBlock{
    NSMutableDictionary * dic = [NSMutableDictionary dictionary];
    [dic setValue:@([pageindex integerValue] * 5) forKey:@"pageindex"];
    [dic setValue:@(5) forKey:@"pagesize"];
    [dic setValue:idString forKey:@"classid"];
    [YBAFNetWorkingTool postWithUrlString:@"getTopicClassRequiredElectiveCourseListUseWeicatTwo" Parameter:dic Success:successBlock Fail:failBlock];
}

#pragma mark 专题是否报名
+ (void)request_objectIsSignInWithIdString:(NSString *)idString successBlock:(NetBlock)successBlock failBlock:(NetBlock)failBlock{
    NSMutableDictionary * dic = [NSMutableDictionary dictionary];
    [dic setValue:YBUSERINFOMODEL.studentId forKey:@"studentid"];
    [dic setValue:idString forKey:@"classid"];
    [YBAFNetWorkingTool postWithUrlString:@"GetIsSignUp" Parameter:dic Success:successBlock Fail:failBlock];
}

#pragma mark 同步专题进度数据
+ (void)request_synchronousClassDataWithIdString:(NSString *)idString successBlock:(NetBlock)successBlock failBlock:(NetBlock)failBlock{
    NSMutableDictionary * dic = [NSMutableDictionary dictionary];
    [dic setValue:YBUSERINFOMODEL.studentId forKey:@"studentid"];
    [dic setValue:YBUSERINFOMODEL.accountId forKey:@"accountid"];
    [dic setValue:YBUSERINFOMODEL.userid forKey:@"sourceuserid"];
    [dic setValue:idString forKey:@"classid"];
    [YBAFNetWorkingTool postWithUrlString:@"calctopicprogress" Parameter:dic Success:successBlock Fail:failBlock];
}

#pragma mark 专题学习进度
+ (void)request_objectGetClassProgressWithIdString:(NSString *)idString successBlock:(NetBlock)successBlock failBlock:(NetBlock)failBlock{
    NSMutableDictionary * dic = [NSMutableDictionary dictionary];
    [dic setValue:YBUSERINFOMODEL.studentId forKey:@"studentid"];
    [dic setValue:idString forKey:@"classid"];
    [YBAFNetWorkingTool postWithUrlString:@"getAppTopicClassProgress" Parameter:dic Success:successBlock Fail:failBlock];
}

#pragma mark 专题培训结业考试(最高)
+ (void)request_objectGetExamInfoWithIdString:(NSString *)idString successBlock:(NetBlock)successBlock failBlock:(NetBlock)failBlock{
    NSMutableDictionary * dic = [NSMutableDictionary dictionary];
    [dic setValue:YBUSERINFOMODEL.studentId forKey:@"userid"];
    [dic setValue:idString forKey:@"classid"];
    [YBAFNetWorkingTool postWithUrlString:@"getExamInfo" Parameter:dic Success:successBlock Fail:failBlock];
}

#pragma mark 专题培训结业考试(当前)
+ (void)request_objectGetCurrentExamInfoWithIdString:(NSString *)idString successBlock:(NetBlock)successBlock failBlock:(NetBlock)failBlock{
    NSMutableDictionary * dic = [NSMutableDictionary dictionary];
    [dic setValue:YBUSERINFOMODEL.studentId forKey:@"userid"];
    [dic setValue:idString forKey:@"classid"];
    [YBAFNetWorkingTool postWithUrlString:@"getLastExamDetailsInfo" Parameter:dic Success:successBlock Fail:failBlock];
}

#pragma mark 报名： SignUp 和审核：insertsy_class_Approval
+ (void)request_objectSignInWithIdString:(NSString *)idString successBlock:(NetBlock)successBlock failBlock:(NetBlock)failBlock{
    NSMutableDictionary * dic = [NSMutableDictionary dictionary];
    [dic setValue:idString forKey:@"classid"];
    [YBAFNetWorkingTool postWithUrlString:@"insertsy_class_approval" Parameter:dic Success:successBlock Fail:failBlock];
    
    
}

#pragma mark 评价
+ (void)request_ybCommitClassWithClasscourseid:(NSString *)classcourseid coursewareid:(NSString *)coursewareid classid:(NSString *)classid scoreList:(NSArray *)scoreList successBlock:(NetBlock)successBlock failBlock:(NetBlock)failBlock{
    NSMutableDictionary * tempDic = [NSMutableDictionary dictionary];
    [tempDic setValue:YBUSERINFOMODEL.accountId forKey:@"accountid"];
    [tempDic setValue:classcourseid forKey:@"classcourseid"];
    [tempDic setValue:YBUSERINFOMODEL.studentId forKey:@"studentid"];
    [tempDic setValue:coursewareid forKey:@"coursewareid"];
    [tempDic setValue:classid forKey:@"classid"];
    NSString * scoreListString = @"[]";
    
    if (scoreList.count > 0) {
        NSMutableArray * fullArray = [NSMutableArray array];
        [scoreList enumerateObjectsUsingBlock:^(NSDictionary *  _Nonnull dic, NSUInteger idx, BOOL * _Nonnull stop) {
            NSString * tempString = @"";
            NSMutableArray * valueArray = [NSMutableArray array];
            NSArray * allKey = dic.allKeys;
            for (NSString * key in allKey) {
                NSString * tempValue = dic[key];
                NSString * value = @"";
                if ([key isEqualToString:@"isReadonly"]) {
                    if ([dic[key] integerValue] == 0) {
                        value = [NSString stringWithFormat:@"\"%@\":false" , key];
                    }
                    else{
                        value = [NSString stringWithFormat:@"\"%@\":true" , key];
                    }
                }
                else{
                    if ([dic[key] isKindOfClass:[NSNumber class]]) {
                        value = [NSString stringWithFormat:@"%@" , dic[key]];
                        value = [NSString stringWithFormat:@"\"%@\":%@" , key , value];
                    }
                    else{
                        value = [NSString stringWithFormat:@"%@" , dic[key]];
                        value = [NSString stringWithFormat:@"\"%@\":\"%@\"" , key , value];
                    }
                }
                
                [valueArray addObject:value];
            }
            tempString = [valueArray componentsJoinedByString:@","];
            [fullArray addObject:[NSString stringWithFormat:@"{%@}" , tempString]];
        }];
        scoreListString =[NSString stringWithFormat:@"[%@]" , [fullArray componentsJoinedByString:@","]];
    }
    
    [tempDic setValue:scoreListString forKey:@"scoreList"];
    [YBAFNetWorkingTool postWithUrlString:@"submitAppraise" Parameter:tempDic Success:successBlock Fail:failBlock];
}


#pragma mark 轮播图新闻页
+ (void)request_homeBannerNewsWithIdString:(NSString *)idString successBlock:(NetBlock)successBlock failBlock:(NetBlock)failBlock{
    NSMutableDictionary * dic = [NSMutableDictionary dictionary];
    [dic setValue:idString forKey:@"newsid"];
    [YBAFNetWorkingTool postWithUrlString:@"selectFrontNewsDetail" Parameter:dic Success:successBlock Fail:failBlock];
    
    
}

@end
